package com.dylan.历史.算法;

/**
 * @author : ankang
 * @date : 2019/10/17 20:43
 * @Description : 在数组中查找大于等于指定值的最小值
 */
public class 基础_查找_二分查找_GE {

    public static void main(String[] args) {
        System.out.println(searchGe(new int[]{1, 2}, 0, 1, 3));
    }

    private static int searchGe(int[] nums, int l, int r, int val) {
        while (l <= r) {
            int m = (l + r) / 2;
            if (nums[m] >= val) {
                if (m == l || nums[m - 1] < val) {
                    return m;
                } else {
                    r = m - 1;
                }
            } else {
                l = m + 1;
            }
        }
        return -1;
    }
}
